import http from '../utils/http';

/**
 * 获取列表
 */
function getDefinitions(){
    return new Promise((resolve, reject) => {
        http("get",'/act/repository/getDefinitions').then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

//save bpmn
function addByString(xml){
    return new Promise((resolve, reject) => {
        http("post",'/act/repository/addByString',{xmlBPMN:xml,deployName:"testxj001"}).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

//getDef
function getDef(procId){
    return new Promise((resolve, reject) => {
        http("get",'/act/repository/getDefById',{id: procId}).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

//delDef
function delDef(deploymentId){
    return new Promise((resolve, reject) => {
        http("get",'/act/repository/delDefinition',{deploymentId: deploymentId}).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}
//query process instance by start user

function getProcessInstancesByUserId(){
    return new Promise((resolve, reject) => {
        http("get",'/act/runtime/getProcessInstancesByUserId').then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


//query my task

function getMyTask(){
    return new Promise((resolve, reject) => {
        http("get",'/act/task/getTaskByAssignee').then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


//query my  finsih task

function getMyFinishTask(){
    return new Promise((resolve, reject) => {
        http("get",'/act/history/myFinishTask').then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


//历史流程高亮
function getHighlight(instanceId) {
    return new Promise((resolve, reject) => {
        http("get",'/act/history/getHighlight',{instanceId:instanceId}).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}




export {
    getDefinitions,addByString,getDef,delDef,getProcessInstancesByUserId,getMyTask,getHighlight,getMyFinishTask

}

